package com.example.headlines.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.headlines.R;
import com.example.headlines.adapter.CollectAdapter;
import com.example.headlines.adapter.HomeAdapter;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;


public class CollectFragment extends Fragment {
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "学校要闻","新闻速递","院系风采","抗疫专栏"
    };
    private ViewPager viewPager;
    private SlidingTabLayout slidingTabLayout;
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private List<String> contents;
    private List<String> contents1;
    private List<String> contents2;
    private List<String> contents3;


    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public CollectFragment() {
    }

    public static CollectFragment newInstance(List<String> contents,List<String> contents1,List<String> contents2,List<String> contents3)  {
        CollectFragment fragment = new CollectFragment();
        fragment.contents=contents;
        fragment.contents1 =contents1;
        fragment.contents2=contents2;
        fragment.contents3 =contents3;
        return fragment;
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.fragment_collect, container, false);
        viewPager = v.findViewById(R.id.fixedViewPager2);
        slidingTabLayout = v.findViewById(R.id.slidingTabLayout);
        return v;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
//        for (String title : mTitles) {
//            mFragments.add(VideoFragment.newInstance(title,contents));
//        }
        for (int m = 0; m < mTitles.length; m++) {
            String title = mTitles[m];
            switch (m) {
                case 0:
                    mFragments.add(VideoFragment2.newInstance(title, contents));
                    break;
                case 1:
                    mFragments.add(VideoFragment2.newInstance(title, contents1));
                    break;
                case 2:
                    mFragments.add(VideoFragment2.newInstance(title, contents2));
                    break;

                case 3:
                    mFragments.add(VideoFragment2.newInstance(title, contents3));
                    break;
                default:break;
            }


        }
        viewPager.setOffscreenPageLimit(mFragments.size());
        viewPager.setAdapter(new CollectAdapter(getFragmentManager(), mTitles, mFragments));
        slidingTabLayout.setViewPager(viewPager);
    }

}